package com.guli.mall.pms.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.guli.mall.pms.entity.AttrEntity;
import com.guli.mall.pms.entity.vo.AttrAttrgroupRelationVo;
import com.guli.mall.pms.entity.vo.AttrTipsVo;
import com.guli.mall.pms.entity.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;

import com.guli.mall.pms.entity.AttrAttrgroupRelationEntity;
import com.guli.mall.pms.service.AttrAttrgroupRelationService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;


/**
 * 属性&属性分组关联
 *
 * @author 罗俊华
 * @email 1007052116@qq.com
 * @date 2020-09-17 11:37:22
 */
@RestController
@RequestMapping("pms/attrattrgrouprelation")
public class AttrAttrgroupRelationController {
    @Autowired
    private AttrAttrgroupRelationService attrAttrgroupRelationService;


    @PostMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取attrAttrgroupRelation分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size,
                  @RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelationEntity) {
        PageUtils<AttrAttrgroupRelationVo> page = attrAttrgroupRelationService.queryPage(currentPage, size, attrAttrgroupRelationEntity);

        return R.ok().put("page", page);
    }


    @GetMapping("/info/{id}")
    @ApiOperation("根据id获取AttrAttrgroupRelation")
    public R info(@PathVariable("id") Long id) {
        AttrAttrgroupRelationEntity attrAttrgroupRelation = attrAttrgroupRelationService.getById(id);

        return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    @PostMapping("/save")
    @ApiOperation("插入AttrAttrgroupRelation")
    public R save(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation) {
        attrAttrgroupRelationService.save(attrAttrgroupRelation);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据id更新AttrAttrgroupRelation")
    public R update(@RequestBody AttrAttrgroupRelationEntity attrAttrgroupRelation) {
        attrAttrgroupRelationService.updateById(attrAttrgroupRelation);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据id批量删除AttrAttrgroupRelation")
    public R delete(@RequestBody Long[] ids) {
        attrAttrgroupRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @PostMapping("/getAvailableBindingAttr/{currentPage}/{size}")
    @ApiOperation("获取该属性分组可以绑定的属性")
    public R getAvailableBindingAttr(@RequestBody AttrAttrgroupRelationVo attrAttrgroupRelationVo,
                                     @PathVariable("currentPage") Integer currentPage,
                                     @PathVariable("size") Integer size) {

        PageUtils<AttrTipsVo> list = attrAttrgroupRelationService.getAvailableBindingAttr(attrAttrgroupRelationVo,currentPage,size);

        return R.ok().put("page",list);

    }

}
